#include<bits/stdc++.h>
using namespace std;
int n[100005],m[100005],l[100005],vv[100005],d[100005],v[100005],a[100005],p[100005],u[100005],t;
void ssolve1(int x)
{
	int s=0;
	for(int i=1;i<=n[x];i++)
	{
		if(v[i]>vv[i]) s++;
	}
	cout<<s<<" "<<m[x]-1;
}
int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	for(int i=1;i<=t;i++)
	{
		cin>>n[i]>>m[i]>>l[i]>>vv[i];
		for(int j=1;j<=n[i];j++)
		{
			u[i]=-100005;
		}
		for(int j=1;j<=n[i];j++)
		{
			cin>>d[j]>>v[j]>>a[j];
			u[j]=max(a[j],u[j]);
		}
		for(int j=1;j<=m[i];j++)
		{
			cin>>p[j];
		}
		for(int i=1;i<=n[i];i++)
		{
			ssolve1(i);
			cout<<"\n";
		}
	}
	return 0;
}
